﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Activities;

namespace VMWareActivities
{
    using Microsoft.TeamFoundation.Build.Client;

    using VMware.Vim;

    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class GetVMPowerStateActivity : CodeActivity
    {
        /// <summary>
        /// Gets or sets the virtual machine.
        /// </summary>
        /// <value>The virtual machine.</value>
        [RequiredArgument]
        public InArgument<VirtualMachine> VirtualMachine { get; set; }

        /// <summary>
        /// Gets or sets the state of the virtual machine power.
        /// </summary>
        /// <value>The state of the virtual machine power.</value>
        [RequiredArgument]
        public OutArgument<VirtualMachinePowerState> VirtualMachinePowerState { get; set; }

        /// <summary>
        /// When implemented in a derived class, performs the execution of the activity.
        /// </summary>
        /// <param name="context">The execution context under which the activity executes.</param>
        protected override void Execute(CodeActivityContext context)
        {
            VirtualMachine virtualMachine = context.GetValue(this.VirtualMachine);
            virtualMachine.UpdateViewData();
            context.SetValue(this.VirtualMachinePowerState, virtualMachine.Runtime.PowerState);
        }
    }
}
